//
// Created by guoshunw on 24-4-1.
//

#ifndef CMAKE_HELLO_OMX_CALLBACK_BASE_H
#define CMAKE_HELLO_OMX_CALLBACK_BASE_H

#include "app_context.h"

#include <OMX_Core.h>
struct tsem_t;

namespace openmax {
    namespace test {
        class AppContext;
    }
    namespace callback {

        class [[maybe_unused]] OMXCallbackBase : public OMX_CALLBACKTYPE {
        public:
            explicit OMXCallbackBase(test::AppContext *appCtx, OMX_STRING componentName, tsem_t *event_sem);

        protected:
            virtual OMX_ERRORTYPE VEventHandler(
                    OMX_IN OMX_HANDLETYPE hComponent,
                    OMX_IN OMX_EVENTTYPE eEvent,
                    OMX_IN OMX_U32 nData1,
                    OMX_IN OMX_U32 nData2,
                    OMX_IN OMX_PTR pEventData) { return OMX_ErrorNone; }

            virtual OMX_ERRORTYPE VEmptyBufferDone(
                    OMX_IN OMX_HANDLETYPE hComponent,
                    OMX_IN OMX_BUFFERHEADERTYPE *pBuffer) { return OMX_ErrorNone; }

            virtual OMX_ERRORTYPE VFillBufferDone(
                    OMX_IN OMX_HANDLETYPE hComponent,
                    OMX_IN OMX_BUFFERHEADERTYPE *pBuffer) { return OMX_ErrorNone; }

            openmax::test::AppContext *app_ctx_{};

        private:
            OMX_ERRORTYPE BaseEventHandler(
                    OMX_IN OMX_HANDLETYPE hComponent,
                    OMX_IN OMX_EVENTTYPE eEvent,
                    OMX_IN OMX_U32 nData1,
                    OMX_IN OMX_U32 nData2,
                    OMX_IN OMX_PTR pEventData);

            OMX_ERRORTYPE BaseEmptyBufferDone(
                    OMX_IN OMX_HANDLETYPE hComponent,
                    OMX_IN OMX_BUFFERHEADERTYPE *pBuffer);

            OMX_ERRORTYPE BaseFillBufferDone(
                    OMX_IN OMX_HANDLETYPE hComponent,
                    OMX_IN OMX_BUFFERHEADERTYPE *pBuffer);


            tsem_t *event_sem_{nullptr};
            OMX_STRING component_name_{};
        };

    }// namespace callback
}// namespace openmax

#endif//CMAKE_HELLO_OMX_CALLBACK_BASE_H
